import { ApiHideProperty } from '@nestjs/swagger'
import { IsNumber, IsOptional, IsString } from 'class-validator'
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm'
import { PlayerUser } from '@/modules/user/entities/player-user.entity'

@Entity('subscribe')
export class Subscribe {
  @PrimaryGeneratedColumn('increment')
  @IsNumber()
  subscribeId: number

  /**
   * 预约人手机号
   */
  @Column({ nullable: true })
  @IsString()
  subscribePhone?: string

  /**
   * 预约人 UID
   */
  @Column()
  @IsString()
  userUid: string

  /**
   * 预约人信息
   */
  @ManyToOne(() => PlayerUser, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'userUid', referencedColumnName: 'uid' })
  subscribeUserInfo: PlayerUser

  /**
   * 邀请人 UID
   */
  @Column({ nullable: true })
  @IsString()
  @IsOptional()
  inviteUserUid?: string

  /**
   * 邀请人数据
   */
  @ApiHideProperty()
  @ManyToOne(() => PlayerUser, { onDelete: 'SET NULL' })
  @JoinColumn({ name: 'inviteUserUid', referencedColumnName: 'uid' })
  inviteUserInfo?: PlayerUser

  /**
   * 是否删除
   */
  @ApiHideProperty()
  @Column({ default: false })
  isDeleted?: boolean

  @CreateDateColumn()
  createdAt?: Date

  @UpdateDateColumn()
  updatedAt?: Date
}
